//
// Created by QT on 2023/11/16.
//

#ifndef FOC_PID_H
#define FOC_PID_H


#include <stdint.h>
#include <stdbool.h>



typedef struct pid_ctrl
{
    float kp;
    float ki;
    float kd;
    float kb;
    float lowLimit, upLimit;

    float ts; // PID调节周期

    float integralSum, integralMax;
    bool saturation;

    float lastError, errorSum, errorSumMax;


    float output;

} pid_ctrl_t;


int pid_ctrl_init(pid_ctrl_t* pid, float p, float i, float d, float integralMax, float lowLimit, float upLimit);

float pid_ctrl_current_calc(pid_ctrl_t* pid, float tarIdq, float fdkIdq, float* udq);
float pid_ctrl_speed_calc(pid_ctrl_t* pid, float tarSpeed, float fdkSpeed, float* iqRef);
float pid_ctrl_position_calc(pid_ctrl_t *pid, float tarPos, float fdkPos, float *speed);

#endif //FOC_PID_H
